Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl

Public Class Xsl

    Private Shared ReadOnly XSL_FOLDER_PATH As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xsl")

    Public ReadOnly _Xsl As XslCompiledTransform

    Public Sub New(ByVal filename As String)

        Dim uri As String = Path.Combine(XSL_FOLDER_PATH, filename)
        _Xsl = CompileTransform(uri)

    End Sub

    Private Function CompileTransform(ByVal uri As String) As XslCompiledTransform

        Dim trans As New XslCompiledTransform()
        trans.Load(uri)

        Return trans

    End Function

    Public Function Transform(ByVal reader As XmlReader, ByVal params As XsltArgumentList) As MemoryStream

        Dim ms As New MemoryStream()
        _Xsl.Transform(reader, params, ms)
        ms.Position = 0

        Return ms

    End Function
End Class
